package easy;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2019/2/27 13:20
 */
public class RemoveElement {
    public static void main(String[] args) {
        Solution solution = new RemoveElement().new Solution();
        int[] array = {3, 2, 2, 3};
        System.out.println(solution.removeElement(array, 3));
    }

    private class Solution {
        public int removeElement(int[] nums, int val) {
            int index = -1;
            int count = 0;

            for (int i = 0; i < nums.length; i++) {
                if (nums[i] == val) {
                    index = i;
                    for (int j = i + 1; j < nums.length; j++) {
                        if (nums[j] != val) {
                            nums[index] = nums[j];
                            nums[j] = val;
                            break;
                        }
                    }
                }
            }

            for (int i = nums.length - 1; i >= 0; i--) {
                if (nums[i] == val) {
                    count += 1;
                    continue;
                }
                break;
            }


            return nums.length - count;
        }
    }
}
